#!/bin/bash 
# http://marius.scurtescu.com/

# Licence : GNU GPL

# Dependency
#		jhead
#		zenity

# jhead specific formatting options:
#      %f - original file name without the extension
#      %i - sequence number, for leading zeros use %04i (4 digit padding)

# some of the strftime formatting options:
#      %a - abbreviated weekday name according to the current locale
#      %A - full weekday name according to the current locale
#      %b - abbreviated month name according to the current locale
#      %B - full month name according to the current locale
#      %d - day of the month as a decimal number (range 01 to 31)
#      %H - hour as a decimal number using a 24-hour clock (range 00 to 23)
#      %I - hour as a decimal number using a 12-hour clock (range 01 to 12)
#      %j - day of the year as a decimal number (range 001 to 366)
#      %m - month as a decimal number (range 01 to 12)
#      %M - minute as a decimal number
#      %p - either `am' or `pm' according to the given time value, or the corresponding strings for the current locale
#      %R - time in 24 hour notation
#      %S - second as a decimal number
#      %u - weekday as a decimal number [1,7], with 1 representing Monday
#      %w - day of the week as a decimal, Sunday being 0
#      %y - year as a decimal number without a century (range 00 to 99)
#      %Y - year as a decimal number including the century
#      %% - a literal `%' character 
#
# See documentation of strftime for full list of options. Make sure you don't
# use options that would generate invalid file names (containing / or : for example).

TITLE="Rename Image(s)"
FORMAT="_%Y_%m_%d-%03i"

if [ $# -eq 0 ] ; then
	zenity --error --title="$TITLE" --text="Please select at least one image."
	exit 2
fi

which jhead 2>/dev/null
if [ $? != 0 ] ; then
    zenity --error --title="$TITLE" --text="jhead not found."
	exit 1
fi

FORMAT=`zenity --title "$TITLE" --entry --entry-text="$FORMAT" --text "Rename pattern:"`

if  [ $? != 0 ]; then
	exit 0
fi

LOGFILE=`mktemp -t Image_Rename.XXXXXX`

jhead -nf"$FORMAT" "$@" > $LOGFILE

zenity --text-info --title="$TITLE" --filename=$LOGFILE --width=600 --height=400
rm -f $LOGFILE

